import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class ArraysNeighbouringNumbers {

	public static void main(String[] args) throws IOException {
	 	BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
	 	int arraySize = 0;
	 	boolean isCorrectSize = true;
	 		do {
				System.out.print("Enter array size (integer number >= 0): ");
				try {
					arraySize = Integer.parseInt(input.readLine());
				}	 catch (java.lang.NumberFormatException e) {
						isCorrectSize = true;
					}
				if (arraySize<=0) {
					isCorrectSize = true;
					} 	else 	{
						isCorrectSize = false;			
								}
				if (isCorrectSize) {
					System.out.println("Wrong input.");
				}
			} while (isCorrectSize);
	 	System.out.println("Array size is: "+arraySize);
	 	
	 	float[] array = new float[arraySize];
	 	
	 	boolean isWrongMember = true;;
		while (isWrongMember) {
			System.out.println("Input array (press Enter after each member):");
		 	for (int i=0; i<arraySize; i++) {
		 		isWrongMember = false;
		 		try {
		 			array[i] = Float.parseFloat(input.readLine());
		 			} catch (NumberFormatException e) {
		 				System.out.println("Wrong array member. Starting from the beginning...");
		 				isWrongMember=true;
		 				break;
		 				}
		 	}
		}
	 	System.out.print("You've entered following array: ");
	 	for (int i=0; i<arraySize; i++) {
	 		System.out.print(array[i]+"; ");
	 	}
	 	double[] diff = new double[arraySize-1];
	 	for (int i=0; i<arraySize-1; i++) {
	 		diff[i] = Math.abs(array[i]-array[i+1]);
	 	}
	 	int minDiff = 0;
	 	for (int i=1; i<arraySize-1; i++) {
	 		if (diff[i] < diff[minDiff]) {
	 			minDiff = i;
	 		}
	 	}
	 	System.out.print("\nIndex of the first element of the pair with smallest distance is: ["+minDiff+"]");
	}

}
